//
//  GuestCell.m
//  ChatForHot
//
//  Created by FLY on 2018/10/18.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "GuestCell.h"
#import "GuestModel.h"
@implementation GuestCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
//        self.selectedBackgroundView = [[UIView alloc] init];
        self.backgroundColor = [UIColor clearColor];
        
        [self.contentView addSubview:self.HOTCHATbackView];
        
        [self.contentView addSubview:self.HOTCHATheadImgView];
        [self.contentView addSubview:self.HOTCHATvipImgView];
        [self.contentView addSubview:self.HOTCHATnameLab];
        [self.contentView addSubview:self.HOTCHATinfoLab];
        [self.contentView addSubview:self.HOTCHATdateLab];
        
        [self.HOTCHATheadImgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).mas_offset(15);
            make.width.height.mas_equalTo(50);
            make.centerY.equalTo(self.contentView);
        }];
        [self.HOTCHATvipImgView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(20);
            make.bottom.right.equalTo(self.HOTCHATheadImgView);
        }];
        [self.HOTCHATnameLab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).mas_offset(10);
            make.height.mas_equalTo(24);
            make.left.equalTo(self.HOTCHATheadImgView.mas_right).mas_offset(15);
            make.right.lessThanOrEqualTo(self.HOTCHATdateLab.mas_left).mas_offset(-5);
        }];
        [self.HOTCHATinfoLab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.HOTCHATnameLab);
            make.height.mas_equalTo(22);
            make.bottom.equalTo(self).mas_offset(-10);
            make.right.lessThanOrEqualTo(self).mas_offset(-15);
        }];
        [self.HOTCHATdateLab mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).mas_offset(-15);
            make.height.mas_equalTo(15);
            make.centerY.equalTo(self.HOTCHATnameLab);
            make.width.mas_greaterThanOrEqualTo(80);
        }];
        [self.HOTCHATbackView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(2.5, 5, 2.5, 5));
        }];
    }
    return self;
}
- (void)setModel:(GuestModel *)model{
    _model = model;
    
    self.HOTCHATinfoLab.text = model.other;
    self.HOTCHATnameLab.text = model.nickName;
    NSString *imgStr = @"";
    if ([model.vip isEqualToString:@"1001"]) {
        
        imgStr = @"all_ic_writevip";
        
    }else if ([model.vip isEqualToString:@"1002"]){
        
        imgStr = @"all_ic_diamondsvip";
    }else if ([model.vip isEqualToString:@"1003"] || [model.vip isEqualToString:@"9999"]){
        
        imgStr = @"all_ic_vip";
    }else{
        
        self.HOTCHATvipImgView.hidden = YES;
    }
    [self.HOTCHATheadImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIHEADER,model.headPic]] placeholderImage:[UIImage imageNamed:@"personal_atatar_but_h"]];
    
    self.HOTCHATvipImgView.image = [UIImage imageNamed:imgStr];
    self.HOTCHATdateLab.text = [self HOTCHATgettime:model.date];
}
//lazzy
-(UIImageView *)HOTCHATheadImgView{
    if (_HOTCHATheadImgView == nil) {
        _HOTCHATheadImgView = [[UIImageView alloc] init];
        _HOTCHATheadImgView.layer.cornerRadius = 25;
        _HOTCHATheadImgView.clipsToBounds = YES;
        _HOTCHATheadImgView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _HOTCHATheadImgView;
}
- (UIImageView *)HOTCHATvipImgView{
    if (_HOTCHATvipImgView == nil) {
        _HOTCHATvipImgView = [[UIImageView alloc] init];

    }
    return _HOTCHATvipImgView;
}
- (UILabel *)HOTCHATnameLab{
    if (_HOTCHATnameLab == nil) {
        _HOTCHATnameLab = [[UILabel alloc] init];
        _HOTCHATnameLab.font = [UIFont systemFontOfSize:14];
        _HOTCHATnameLab.textColor = HOTCHATrgb(26, 26, 26);
    }
    return _HOTCHATnameLab;
}
- (UILabel *)HOTCHATinfoLab{
    if (_HOTCHATinfoLab == nil) {
        _HOTCHATinfoLab = [[UILabel alloc] init];
        _HOTCHATinfoLab.font = [UIFont systemFontOfSize:12];
        _HOTCHATinfoLab.textColor = HOTCHATrgb(128, 128, 128);
    }
    return _HOTCHATinfoLab;
}
- (UILabel *)HOTCHATdateLab{
    if (_HOTCHATdateLab == nil) {
        _HOTCHATdateLab = [[UILabel alloc] init];
        _HOTCHATdateLab.font = [UIFont systemFontOfSize:10];
        _HOTCHATdateLab.textColor = HOTCHATrgb(128, 128, 128);
        _HOTCHATdateLab.textAlignment = NSTextAlignmentRight;
    }
    return _HOTCHATdateLab;
}
- (UIView *)HOTCHATbackView{
    if (_HOTCHATbackView == nil) {
        _HOTCHATbackView = [[UIView alloc] init];
        _HOTCHATbackView.backgroundColor = [UIColor whiteColor];
        _HOTCHATbackView.layer.cornerRadius = 8;
//        _HOTCHATbackView.clipsToBounds = YES;
//        _HOTCHATbackView.layer.borderColor = ONENIGHTrgb(230,230,230).CGColor;
//        _HOTCHATbackView.layer.borderWidth = 0.5;
    }
    return _HOTCHATbackView;
}


- (NSString *)HOTCHATgettime:(NSString *)time
{
    double timeInterval = time.longLongValue ;
    if(timeInterval > 140000000000) {
        timeInterval = timeInterval / 1000;
    }
    NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSString *latestMessageTime = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:timeInterval]];
    
    return latestMessageTime;
}
@end
